// 引入 request 方法，假设 request 方法已经定义在某个工具文件中
import request from '/@/utils/request';
import { 
    DeleteFileInput,
    PageFileInput,
    SysFile,
    UploadFileFromBase64Input,
} from '../models';
// 定义 API 路径枚举
enum Api {
    DeleteFile = '/sysFile/delete',
    DownloadFileBase64 = '/sysFile/downloadFileBase64',
    DownloadFile = '/sysFile/downloadFile',
    GetFile = '/sysFile/file',
    GetFilePage = '/sysFile/page',
    PreviewFile = '/sysFile/preview/{id}',
    RelationFiles = '/sysFile/relationFiles',
    UpdateFile = '/sysFile/update',
    UploadAvatar = '/sysFile/uploadAvatar',
    UploadFileFromBase64 = '/sysFile/uploadFileFromBase64',
    UploadFile = '/sysFile/uploadFile',
    UploadFiles = '/sysFile/uploadFiles',
    UploadSignature = '/sysFile/uploadSignature',
}

// 删除文件
export const apiSysFileDeletePost = (body: DeleteFileInput) =>
    request({
        url: Api.DeleteFile,
        method: 'post',
        data: body,
    });

// 下载指定文件Base64格式
export const apiSysFileDownloadFileBase64Post = (body?: string) =>
    request({
        url: Api.DownloadFileBase64,
        method: 'post',
        data: body,
    });

// 根据文件Id或Url下载
export const apiSysFileDownloadFilePost = (body?: SysFile) =>
    request({
        url: Api.DownloadFile,
        method: 'post',
        data: body,
    });

// 获取文件
export const apiSysFileFileGet = (id?: number) =>
    request({
        url: Api.GetFile,
        method: 'get',
        params: { id },
    });

// 获取文件分页列表
export const apiSysFilePagePost = (body?: PageFileInput) =>
    request({
        url: Api.GetFilePage,
        method: 'post',
        data: body,
    });

// 文件预览
export const apiSysFilePreviewIdGet = (id: number) =>
    request({
        url: Api.PreviewFile.replace('{id}', encodeURIComponent(String(id))),
        method: 'get',
    });

// 根据关联查询附件
export const apiSysFileRelationFilesGet = (relationName?: string, relationId?: number, fileTypes?: string, belongId?: number) =>
    request({
        url: Api.RelationFiles,
        method: 'get',
        params: { RelationName: relationName, RelationId: relationId, FileTypes: fileTypes, BelongId: belongId },
    });

// 更新文件
export const apiSysFileUpdatePost = (body?: SysFile) =>
    request({
        url: Api.UpdateFile,
        method: 'post',
        data: body,
    });

// 上传头像
export const apiSysFileUploadAvatarPostForm = (file?: Blob) =>
    request({
        url: Api.UploadAvatar,
        method: 'post',
        data: file,
    });

// 上传文件Base64
export const apiSysFileUploadFileFromBase64Post = (body?: UploadFileFromBase64Input) =>
    request({
        url: Api.UploadFileFromBase64,
        method: 'post',
        data: body,
    });

// 上传文件
export const apiSysFileUploadFilePostForm = (file?: Blob, path?: string, savePath?: string, allowSuffix?: string, fileType?: string) =>
    request({
        url: Api.UploadFile,
        method: 'post',
        data: { file, path, savePath, allowSuffix, fileType },
    });

// 上传多文件
export const apiSysFileUploadFilesPostForm = (files?: Array<Blob>) =>
    request({
        url: Api.UploadFiles,
        method: 'post',
        data: files,
    });

// 上传电子签名
export const apiSysFileUploadSignaturePostForm = (file?: Blob) =>
    request({
        url: Api.UploadSignature,
        method: 'post',
        data: file,
    });